//
//  MLHttpHelper.h
//  Meili
//
//  Created by Robin on 15/12/29.
//  Copyright © 2015年 Robin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MYRequest.h"

extern NSString *const HttpCodeKey;
extern NSString *const HttpMessageKey;
extern const NSUInteger HttpRightCode;

typedef void(^successBlock)(NSDictionary *dict);
typedef void(^failedBlock)(NSError *error);

@interface MYHttpHelper : NSObject

+(MYHttpHelper *)shareHelper;

#pragma mark - 非RAC请求
-(MYRequest *)postWithUrl:(NSString *)url
                 params:(__kindof NSDictionary *)params
                success:(successBlock)success
                 failed:(failedBlock)failed;

-(MYRequest *)getWithUrl:(NSString *)url
                params:(__kindof NSDictionary *)params
               success:(successBlock)success
                failed:(failedBlock)failed;

-(MYRequest *)postWithHost:(NSString *)host
                     url:(NSString *)url
                  params:(__kindof NSDictionary *)params
                 success:(successBlock)success
                  failed:(failedBlock)failed;

-(MYRequest *)getWithHost:(NSString *)host
                    url:(NSString *)url
                 params:(__kindof NSDictionary *)params
                success:(successBlock)success
                 failed:(failedBlock)failed;

#pragma mark - RAC请求
-(MYRequest *)rac_postWithUrl:(NSString *)url
                 params:(__kindof NSDictionary *)params
                success:(successBlock)success
                 failed:(failedBlock)failed;

-(MYRequest *)rac_getWithUrl:(NSString *)url
                params:(__kindof NSDictionary *)params
               success:(successBlock)success
                failed:(failedBlock)failed;

-(MYRequest *)rac_postWithHost:(NSString *)host
                     url:(NSString *)url
                  params:(__kindof NSDictionary *)params
                 success:(successBlock)success
                  failed:(failedBlock)failed;

-(MYRequest *)rac_getWithHost:(NSString *)host
                    url:(NSString *)url
                 params:(__kindof NSDictionary *)params
                success:(successBlock)success
                 failed:(failedBlock)failed;

/**
 *  防止空数据，创建一个空信号量
 *
 *  @return 空信号量
 */
+ (RACSignal *)emptySignal;

/**
 数据验证错误信号

 @param msg 错误信息

 @return <#return value description#>
 */
+ (RACSignal *)errorSignalWithMsg:(NSString *)msg;

/**
 判断请求回调是否正确
 
 @param dict <#dict description#>
 
 @return <#return value description#>
 */
+ (BOOL)reqSuccessOfDic:(NSDictionary *)dict;

/**
 判断请求回调是否正确，顺便处理错误信息提示
 
 @param dict <#dict description#>
 
 @return <#return value description#>
 */
+ (BOOL)isSuccessOfDic:(NSDictionary *)dict;

@end
